package com.wicket.okrapp.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wicket.okrapp.common.dto.FieldInfo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wicket.okrapp.base.service.MOmsAccountPlanBillRsService;
import com.wicket.okrapp.common.exception.BizException;
import com.wicket.okrapp.common.util.CommonFunctionHelper;
import com.wicket.okrapp.dal.mapper.mbg.OmsAccountPlanBillRsMapper;
import com.wicket.okrapp.dal.po.mbg.OmsAccountPlanBillRs;
import com.wicket.okrapp.base.service.dto.req.*;
//import com.wicket.okrapp.base.service.dto.res.*;

import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;

import java.util.*;
import java.util.stream.Collectors;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author ：
 * @since 2022/1/19 15:39
 *
 *
 * @version 1.0
 */
@Service
public class MOmsAccountPlanBillRsServiceImpl
  extends ServiceImpl<OmsAccountPlanBillRsMapper, OmsAccountPlanBillRs>
  implements MOmsAccountPlanBillRsService {

  @Autowired
  OmsAccountPlanBillRsMapper omsAccountPlanBillRsMapper;
/**
   * 3-9-03批量增规划账户下账单[2855]
   * gen by moon at 8/28/2022, 4:29:01 PM
   */
 @Trace(operationName = "3-9-03批量增规划账户下账单")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  batchAddAccountPlanBillRs(List<OmsAccountPlanBillRs> omsAccountPlanBillRs) {
     
      if(omsAccountPlanBillRs==null || omsAccountPlanBillRs.size()==0){
        return false;
      }
      
      return super.saveBatch(omsAccountPlanBillRs.stream().map(item->{
       item.setPlanBillRsId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
          return item;
      }).collect(Collectors.toList()));
  }
/**
   * 3-9-03批量查询规划账户下账单[3255]
   * gen by moon at 8/28/2022, 4:29:01 PM
   */
 @Trace(operationName = "3-9-03批量查询规划账户下账单")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsAccountPlanBillRs>  batchQueryAccountPlanBillRs(BatchQueryAccountPlanBillRsReq reqDto) {

        try {
            QueryWrapper<OmsAccountPlanBillRs> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
reqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
reqDto.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
            if(reqDto.getAccountPlanBillRsList()==null || reqDto.getAccountPlanBillRsList().isEmpty()){
                    return new ArrayList<>();
                }
        queryWrapper.in("plan_account_id", reqDto.getAccountPlanBillRsList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsAccountPlanBillRs.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsAccountPlanBillRs.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsAccountPlanBillRs.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsAccountPlanBillRs>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }
/**
   * 3-9-03批量删规划账户下账单[3256]
   * gen by moon at 8/28/2022, 4:29:02 PM
   */
 @Trace(operationName = "3-9-03批量删规划账户下账单")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  batchDeleteAccountPlanBillRs(List<String> reqDto) {
     
          if(reqDto==null || reqDto.size()==0){
            return false;
          }
          
          return super.removeByIds(reqDto);
  }

}

